Repository navigation
Conversation
2ef14ca to
ca9b6d3
Compare
| }); | ||
|
|
||
| // Load in the legacy custom rulesets, if any | ||
| storage.get({legacy_custom_rulesets: false}, item => { |
There was a problem hiding this comment.
This would be simpler with a default value of [] so you can skip the if, and just iterate straight through.
| // Load custom rulesets and add to storage | ||
| await new Promise(resolve => { | ||
| for(let ruleset of settings.custom_rulesets){ | ||
| all_rules.addFromXml((new DOMParser()).parseFromString(ruleset, 'text/xml')); |
There was a problem hiding this comment.
Please factor out a function load_legacy_custom_rulesets, so that you can call it here after you do storage.set.
| all_rules.ruleCache = new Map(); | ||
|
|
||
| // Set/store globals | ||
| storage.set({'httpNowhere': settings.prefs.http_nowhere_enabled}); |
There was a problem hiding this comment.
Is there a reason you provide a callback when calling set above, but not here? It seems like we should use the callback on both, to detect success or failure.
| } | ||
| await Promise.all(rule_toggle_promises); | ||
|
|
||
| all_rules.ruleCache = new Map(); |
There was a problem hiding this comment.
Can you add a comment explaining why this is needed?
|
|
||
| rule_toggle_promises.push((ruleset_name, ruleset_active => { | ||
| return new Promise(resolve => { | ||
| for(let host in all_rules.targets){ |
There was a problem hiding this comment.
A couple of comments here:
- This doesn't seem to do any async work, so why is it wrapped in a Promise?
- This seems to re-do the work of marking rulesets active or inactive that should happen at startup. Similar to the loading of legacy rulesets I mentioned above, can you just store the settings, and then re-load the rulesets? In fact, since loading the rulesets should include loading legacy_custom_rulesets, you can just do that and don't have to separately invoke the loader for legacy_custom_rulesets.
There was a problem hiding this comment.
This task can take quite a while, since it's iterating through all ruleset targets and checking all rules they contain until finding a match. Creating a new promise for each of these isn't to resolve callbacks, but to start asynchronous program flow for each of these potentially many toggles.
There was a problem hiding this comment.
Since this is javascript and not actually dedicating separate cores to the problem, it does not necessarily give us any efficiency gain to split this up into multiple iterations of the event loop. I can refactor this to be synchronous.
| // Set/store globals | ||
| storage.set({'httpNowhere': settings.prefs.http_nowhere_enabled}); | ||
| storage.set({'showCounter': settings.prefs.show_counter}); | ||
| isExtensionEnabled = settings.prefs.global_enabled; |
There was a problem hiding this comment.
This setting doesn't seem to get stored?
There was a problem hiding this comment.
It's true, the extension enabled toggle is not stored (and has never been). We should fix that but I figured it was outside of the scope of this PR.
There was a problem hiding this comment.
Oh, interesting! I did not know that. It seems weird to apply this toggle only on first run after an upgrade, though. If storing it doesn't work, I'd suggest just removing this line.
|
@Hainish Also, can you already code this in StandardJS style or the style of your choice (I recommend Standard)? |
| rsync -aL --delete --delete-excluded --exclude /chrome/content/rules src/ pkg/xpi-eff | ||
| cp -a translations/* pkg/xpi-eff/chrome/locale/ | ||
|
|
||
| # The next lines are for embedded WebExtensions, and can be deleted after the full transition to WebExtensions |
There was a problem hiding this comment.
You should probably include a footer indicating the end of the lines that can be deleted after the full transition.
| if (msg == "import-legacy-data") { | ||
| let globals = get_prefs("extensions.https_everywhere."); | ||
| let prefs_array = globals.getChildList("", {}); | ||
| if(~prefs_array.indexOf("webextensions-migrated") ? !globals.getBoolPref("webextensions-migrated") : true){ |
There was a problem hiding this comment.
This if statement is overly complicated. In particular, :? operators are ideally avoided because they are hard to read and error prone. Embedding a :? inside an if makes that especially so. :-) Can you break it out for clarity? Also, the ~ operator is a new idiom in this codebase. I think it would be better not to introduce it in such a large change without strong motivation.
| let changed = false; | ||
|
|
||
| let prefs = { | ||
| http_nowhere_enabled: ~prefs_array.indexOf("http_nowhere.enabled") ? globals.getBoolPref("http_nowhere.enabled") : false, |
There was a problem hiding this comment.
This pattern of "check if pref exists, return default value if not" should be a small helper function.
| let globals = get_prefs("extensions.https_everywhere."); | ||
| let prefs_array = globals.getChildList("", {}); | ||
| if(~prefs_array.indexOf("webextensions-migrated") ? !globals.getBoolPref("webextensions-migrated") : true){ | ||
| let rules = get_prefs("extensions.https_everywhere.rule_toggle."); |
There was a problem hiding this comment.
Move let rules and let changed down to right before they are used.
There was a problem hiding this comment.
I agree for rules, but for changed it seems this is a var which is featured prominently throughout this scope. I'd argue that it's appropriate to keep it at the top.
| updateState(); | ||
| } else if (message.type == "remove_rule") { | ||
| removeRule(message.object); | ||
| } else if (message.type == "import_settings") { |
There was a problem hiding this comment.
Can you add a comment explaining when this is used? I.e., importing from the Options page rather than automatically from the parent extension?
ca9b6d3 to
aa68e92
Compare
aa68e92 to
e70a968
Compare
e70a968 to
100fdde
Compare
| for(let ruleset_name in settings.rule_toggle){ | ||
| localStorage[ruleset_name] = settings.rule_toggle[ruleset_name]; | ||
|
|
||
| (ruleset_name, ruleset_active => { |
There was a problem hiding this comment.
Did you see my earlier comment about just storing the data and reloading? E.g. all_rules = new RuleSets(localStorage)
There was a problem hiding this comment.
Ah! Didn't catch that. Fixing now.
| })(ruleset_name, settings.rule_toggle[ruleset_name]); | ||
| } | ||
|
|
||
| // This is necessary in order to clear the cache for any previous ruleset lookups |
There was a problem hiding this comment.
If you do the reload, this won't be necessary anymore.
| await new Promise(resolve => { | ||
| storage.set({'showCounter': settings.prefs.show_counter}, resolve); | ||
| }); | ||
| isExtensionEnabled = settings.prefs.global_enabled; |
There was a problem hiding this comment.
Did you see my comment about removing this since it will only work once, and is therefore inconsistent/confusing?
100fdde to
a674977
Compare
required due to use of async functions.
a674977 to
bd23706
Compare
|
Ready for review again. |
a44f7f1 to
3386b94
Compare
|
Hold on, for some reason the default rulesets are absent when the second call of |
|
Do you mutate the argument in the |
|
@koops76 not in a way that would cause targets to be lost |
|
Try making a copy of everything in |
|
I figured it out.... |
ghost
left a comment
There was a problem hiding this comment.
Good overall. 👍🏻
Sorry for such a large amount of comments.
| all_rules = new RuleSets(localStorage); | ||
|
|
||
| // Set/store globals | ||
| await new Promise(resolve => { |
| @@ -0,0 +1,17 @@ | |||
| .section-header{ | |||
There was a problem hiding this comment.
Add a space between the { and the selector.
| <script src="send-message.js"></script> | ||
| </head> | ||
| <body> | ||
| <div id='import-confirmed' i18n="options_imported"></div> |
| <head> | ||
| <meta charset="utf-8"> | ||
| <link href="options.css" rel="stylesheet" type="text/css"/> | ||
| <script src="options.js"></script> |
There was a problem hiding this comment.
Move the scripts to the end of body tag.
| document.addEventListener("DOMContentLoaded", () => { | ||
|
|
||
| let json_data; | ||
| let import_button = document.querySelector("#import"); |
| if(!pref_retrieve_bool_with_default(globals, "webextension-migrated", false)){ | ||
| let changed = false; | ||
|
|
||
| let prefs = { |
| changed = true; | ||
| } | ||
|
|
||
| let rule_toggle = {} |
| } | ||
|
|
||
| let rule_toggle = {} | ||
| let rules = get_prefs("extensions.https_everywhere.rule_toggle."); |
|
|
||
| let rule_toggle = {} | ||
| let rules = get_prefs("extensions.https_everywhere.rule_toggle."); | ||
| for(let rule_toggle_key of rules.getChildList("", {})){ |
| changed = true; | ||
| } | ||
|
|
||
| let custom_rulesets = get_custom_rulesets_array(); |
|
@jsha There's a problem with loading the XML for legacy rulesets in the constructor. The rules themselves aren't stored in I therefore propose that we keep the previous workflow for loading rulesets. |
This reverts commit 3386b94.
|
That sounds fine for now, although I think the localStorage distinction is a bit of a red herring, since the custom rules get stored in the LGTM, modulo @koops76's feedback, and fixing the tests. |
|
@jsha, great, I'll change it back to the way it was and merge master into this branch (so the tests pass). Can you give me a final LGTM before I pull the trigger? |
|
Sure, will check back later tonight. |
|
@koops76 thanks for the feedback. Since we are trying to get this out the door, I'd like to save that for a further refactor. |
|
@Hainish No problem. |
957b3ce to
0d1954a
Compare
| })(ruleset_name, settings.rule_toggle[ruleset_name]); | ||
|
|
||
| // This line is necessary to clear cached lookups of rulesets already loaded | ||
| all_rules.ruleCache = new Map(); |
There was a problem hiding this comment.
I think you reverted too far. You had an intermediate branch that looked good where you skipped the multiply-nested for loops above, and called all_rules = new RuleSet(localStorage). That will work fine if you just much load_legacy_custom_rulesets(...) below new RuleSet
There was a problem hiding this comment.
@jsha we'd have to copy lines 27-32 as well...
// Allow users to enable `platform="mixedcontent"` rulesets
var enableMixedRulesets = false;
storage.get({enableMixedRulesets: false}, function(item) {
enableMixedRulesets = item.enableMixedRulesets;
all_rules.addFromXml(loadExtensionFile('rules/default.rulesets', 'xml'));
}); There was a problem hiding this comment.
Otherwise we'll have the problem I mentioned in #11792 (comment).
There was a problem hiding this comment.
We could do
all_rules = new RuleSet(localStorage);
all_rules.addFromXml(loadExtensionFile('rules/default.rulesets', 'xml'));
load_legacy_custom_rulesets(settings.custom_rulesets);Which is probably fine for now, but seems like we may run into complications when we are working on merging sign-rulesets. Though I can take care of that problem when we come to it, I suppose.
575f4d7 to
32bd342
Compare
|
@jsha ready for final review |
| async function import_settings(settings){ | ||
| if(settings.changed){ | ||
| // Load custom rulesets and add to storage | ||
| await new Promise(resolve => { |
There was a problem hiding this comment.
Do we really need to wait until the settings are stored?
There was a problem hiding this comment.
@koops76 we do for the options ui. We only want to display the Settings imported string once the settings have actually been imported.
There was a problem hiding this comment.
Then use Promise.all to await all four promises.
|
@Hainish My opinion is: it's OK, but has repetitive code that must be moved into a function and you probably do not need to wait until the settings are stored, or instead you could use |
| return null; | ||
| }, | ||
|
|
||
| addHostnameToTab: function(tabId, ruleset_name, hostname) { |
There was a problem hiding this comment.
Looks like the "addHostnameToTab" work snuck back in by accident.
There was a problem hiding this comment.
@jsha this is just because this was forked from the first iteration of firefox-webextensions-core - should I rebase it?
There was a problem hiding this comment.
I could rebase from master, now that firefox-webextensions-core is merged.
|
New PR, rebased from master: #11800 |
|
I'll review that, but it probably would have been easier to merge rather than rebase. |
|
The thing is that this PR was a request to merge in to a branch that was eventually rebased before being merged into master, so the whole history got a bit unwieldy. Let's try doing all merges next time.
…On August 9, 2017 8:02:49 PM PDT, Jacob Hoffman-Andrews ***@***.***> wrote:
I'll review that, but it probably would have been easier to merge
rather than rebase.
--
You are receiving this because you modified the open/close state.
Reply to this email directly or view it on GitHub:
#11792 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
No description provided.